<?php

namespace App\Containers\AppSection\Accreditation\Models;

use App\Containers\AppSection\Profile\Models\Profile;
use App\Ship\Parents\Models\Model;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

/**
 * Аккредитация
 *
 * @property int $id Id
 * @property int $user_id Владелец
 * @property int $moderator_id Модератор
 * @property string $stage Стадия
 * @property Carbon $created_at Время создания
 * @property Carbon $updated_at Время обновления
 *
 * @property Profile $profile Профиль
 * @property Profile $moderator Модератор
 * @property Remark $remarks Заметки
 */
class Accreditation extends Model
{
    protected $fillable = [
        'profile_id',
        'moderator_id',
        'stage',
    ];

    protected $dates = [
        'created_at',
        'updated_at',
    ];

    /**
     * A resource key to be used in the serialized responses.
     */
    protected string $resourceKey = 'Accreditation';

    /**
     * Профиль
     * @return BelongsTo Profile
     */
    public function profile(): BelongsTo
    {
        return $this->belongsTo(Profile::class, 'profile_id', 'id');
    }

    /**
     * Модератор
     * @return BelongsTo Profile
     */
    public function moderator(): BelongsTo
    {
        return $this->belongsTo(Profile::class, 'moderator_id', 'id');
    }

    /**
     * Профили
     * @return HasOne|Profile Profiles
     */
    public function profiles(): HasOne
    {
        return $this->hasOne(Profile::class, 'accreditation_id', 'id');
    }

    /**
     * Заметки
     * @return HasMany|Remark Remarks
     */
    public function remarks(): HasMany
    {
        return $this->hasMany(Remark::class, 'accreditation_id', 'id');
    }

    public function hasStage($stage): bool
    {
        return $this->stage === $stage;
    }
}
